﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace DiscoveryLogic.DataViz.NetworkDiagram.NetworkData
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public abstract class BaseEntity
    {
        private EntityType _EntityType;
        /// <summary></summary>
        public EntityType EntityType
        {
            get
            {
                return this._EntityType;
            }
        }

        private readonly string _IdField;
        private readonly string _NameField;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="idField"></param>
        /// <param name="nameField"></param>
        public BaseEntity(EntityType entityType, string idField, string nameField)
        {
            this._EntityType = entityType;
            this._IdField = idField;
            this._NameField = nameField;
        }

        /// <summary>
        /// 
        /// </summary>
        public string PKValue()
        {
            PropertyInfo pkProp = this.GetType().GetProperty(this._IdField);
            return pkProp.GetValue(this, null).ToString();
        }

        /// <summary>
        /// 
        /// </summary>
        public string Name()
        {
            if (!string.IsNullOrEmpty(this._NameField))
            {
                PropertyInfo nameProp = this.GetType().GetProperty(this._NameField);
                return nameProp.GetValue(this, null).ToString();
            }
            else
                return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="propName"></param>
        /// <returns></returns>
        public object GetPropertyValue(string propName)
        {
            PropertyInfo prop = this.GetType().GetProperty(propName);
            if (prop != null)
                return prop.GetValue(this, null);
            else
                return null;
        }

        /// <summary>
        /// 
        /// </summary>
        public abstract List<string> GetDescriptiveFieldNames();

        /// <summary>
        /// 
        /// </summary>
        public abstract List<string> GetIdentifyingFieldNames();

        /// <summary>
        /// 
        /// </summary>
        public abstract List<string> GetAssociativeFieldNames();
    }
}
